package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.core.injector.methods.UpdateById;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.core.utils.RequestUtil;
import com.weixing.mall.provider.mapper.SubSiteMapper;
import com.weixing.mall.provider.model.domain.SubSite;
import com.weixing.mall.provider.model.dto.cms.SubSiteChgEnableDto;
import com.weixing.mall.provider.model.dto.cms.SubSiteDto;
import com.weixing.mall.provider.model.vo.SubSiteVo;
import com.weixing.mall.provider.service.ISubSiteService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author wx
 * @Date 2019/7/25 16:11
 * @Version 1.0
 */
/**
 * <p>
 * 子站管理表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-18
 */
@Service
public class SubSiteServiceImpl extends ServiceImpl<SubSiteMapper, SubSite> implements ISubSiteService {

    @Override
    public IPage<SubSiteVo> selectOfPage(Page page) {

        return baseMapper.selectOfPage(page);
    }

    @Override
    public void save(SubSiteDto subSiteDto) {

        SubSite subSite = new SubSite();
        BeanUtils.copyProperties(subSiteDto,subSite);
        subSite.setIsEnable(subSiteDto.getIsEnable().getValue());
        subSite.setSiteType(subSiteDto.getSiteType().getValue());
        if(null==subSiteDto.getId()){
            save(subSite);
        }else {
            updateById(subSite);
        }

    }

    @Override
    public void insert(SubSiteDto subSiteDto) {

    }

    @Override
    public void changeEnable(SubSiteChgEnableDto subSiteChgEnableDto) {
        SubSite subSite = new SubSite();
        subSite.setId(subSiteChgEnableDto.getId());
        subSite.setIsEnable(subSiteChgEnableDto.getIsEnableEnum().getValue());
        updateById(subSite);
    }
}
